package com.jdwx.opengl.mvp.presenter;

import com.jdwx.opengl.mvp.model.entity.Student;
import com.jdwx.opengl.mvp.model.impl.StudentLoginModelImpl;
import com.jdwx.opengl.mvp.ui.MainActivity;
import com.jdwx.opengl.mvp.ui.impl.LoginView;

/**
 * 登陆的Presenter 的接口，实现类为LoginPresenterImpl，完成登陆的验证，以及销毁当前view。
 */
public class LoginPresenterImpl implements LoginPresenter,OnLoginFinishedListener {
    private LoginView loginView;
    private StudentLoginModelImpl studentLoginModelImpl;

    public LoginPresenterImpl(LoginView loginView) {
        this.loginView = loginView;
        this.studentLoginModelImpl = new StudentLoginModelImpl();
    }

    @Override
    public void validateCredentials(Student student) {

        loginView.showProgress();

        studentLoginModelImpl.login( student ,this );

    }

    @Override
    public void onDestroy() {
        loginView = null;
    }


    @Override
    public void onUsernameError() {


        loginView.setUsernameError();

        loginView.hideProgress();

    }

    @Override
    public void onPasswordError() {

        loginView.setPasswordError();
        loginView.hideProgress();
    }

    @Override
    public void onSuccess() {

        loginView.hideProgress();

        loginView.showSuccess();


    }
}
